package cn.edu.neu.vmmigeval.cloud.policy.impl;


import cn.edu.neu.vmmigeval.cloud.entity.Host;
import cn.edu.neu.vmmigeval.cloud.policy.MigratedHostPolicy;

import java.util.LinkedList;
import java.util.List;

public class MigratedHostPolicyOur extends MigratedHostPolicy {
	
	double threshold =0.9;
	
	/*public MigratedHostPolicyDefault(List<Host> hostList,double threshold){
		super(hostList);
		this.threshold = threshold;
	}*/
	
	public MigratedHostPolicyOur(double threshold) {
		super();
		this.threshold = threshold;
	}
	
	@Override
	public List<Host> getOverHosts(List<Host> hosts){
		List<Host> overUtilizedHosts = new LinkedList<Host>();
		for (Host host : hosts) {
			if(host.getActive()==0&&!host.isMigration()){
				double preCpuUtilization = host.getUtilizationHistory().get(host.getUtilizationHistory().size() -1);
				double cpuUtilization = host.getCurrentCpu()/host.getTotalCpu();
				if(preCpuUtilization>=threshold && cpuUtilization>=threshold){
					overUtilizedHosts.add(host);
				}
			}
			
		}
		return overUtilizedHosts;
	}

	@Override
	public boolean isHostOverUtilized(Host host) {
		return false;
	}

	@Override
	public boolean isHostUnderUtilized(Host host) {
		// TODO Auto-generated method stub
		return false;
	}
	
	

}
